// 二分法
#include "stdio.h"
#include "math.h"
#define eps 5e-6
#define delta 1e-6

float Bisection(float a,float b,float( *f)(float))
{
	float c,fc,fa = (*f)(a),fb = (*f)(b);
	int n = 1;
	printf("erfencishu\n");
	while (1){
		if (fa * fb > 0) {
			printf("bunengyogerfenfaqiujie");
			break;
		}
		c = (a+b)/2,fc = (*f)(c);
		printf("%d\t\t%f\t\t%f\n",n++,c,fc);
		if(fabs(fc) < delta) break;
		else if(fa * fc < 0) {b = c;fb = fc;}
		else {a = c;fa = fc;}
		if((b - a) < eps) break;
	}
	return c;
}

float f(float x)
{
	return x*x*x + 4*x*x - 10;
}

int main( )
{
	float a = 1,b = 2;
	float x;
	x = Bisection(a,b,f);
	printf("\nkey is %f",x);
	return 0;
}